﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MessageCommon.GlobalType;
using System.Reflection;

namespace MessageCommon.GlobalStructure
{
    [Serializable]
    public class AddressInfo
    {
        public string strUserId;
        public string strIPAddress;
        public EnumClientType enumClientType;

        public AddressInfo()
        {
            strUserId = string.Empty;
            strIPAddress = string.Empty;
            enumClientType = EnumClientType.PCClient;
        }

        public static bool operator ==(AddressInfo addr1, AddressInfo addr2)
        {
            FieldInfo[] fields = typeof(AddressInfo).GetFields();

            foreach (var f in fields)
            {
                if (f.GetValue(addr1).GetType().IsEnum)
                {
                    if ((int)f.GetValue(addr1) != (int)f.GetValue(addr2))
                    {
                        return false;
                    }
                }
                else
                {
                    if (f.GetValue(addr1).ToString() != f.GetValue(addr2).ToString())
                    {
                        return false;
                    }
                }
            }

            return true;
        }

        public static bool operator !=(AddressInfo addr1, AddressInfo addr2)
        {
            FieldInfo[] fields = typeof(AddressInfo).GetFields();

            foreach (var f in fields)
            {
                if (f.GetValue(addr1).GetType().IsEnum)
                {
                    if ((int)f.GetValue(addr1) != (int)f.GetValue(addr2))
                    {
                        return true;
                    }
                }
                else
                {
                    if (f.GetValue(addr1).ToString() != f.GetValue(addr2).ToString())
                    {
                        return true;
                    }
                }
            }

            return false;
        }
    }

    [Serializable]
    public class AddressInfoList : List<AddressInfo>
    {

    }
}
